import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    tableData : JSON.parse(localStorage.getItem('tableData_json'))?JSON.parse(localStorage.getItem('tableData_json')):[],
    id:localStorage.getItem('id')?localStorage.getItem('id'):1
  },
  mutations: {
    addems: function (state,formName) {
      // let tableData_json1 = localStorage.getItem('tableData_json')
      // //反序列化为对象
      // let tableData = JSON.parse(tableData_json1)
      if (!state.tableData) {
        state.tableData = []
      }
      state.tableData.push(formName)
      let tableData_json = JSON.stringify(state.tableData)
      localStorage.setItem('tableData_json', tableData_json)
    },

    updateems:function (state,obj) {
      let formName=obj.formName
      let index=obj.index
      state.tableData[index]=formName
      // let tableData_json1 = localStorage.getItem('tableData_json')
      // let tableData = JSON.parse(tableData_json1)
      // state.tableData.splice(this.index,1,formName)

      let tableData_json = JSON.stringify(state.tableData)
      localStorage.setItem('tableData_json',tableData_json)
    }
  },
  actions: {
  },
  modules: {
  },
  getters:{

  }
})
